package com.ruoyi.caigou.service.impl;

import com.ruoyi.caigou.mapper.SupplierReportMapper;
import com.ruoyi.caigou.service.ISupplierReportService;
import com.ruoyi.caigou.utils.JasperPdfUtil;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.api.domain.caigou.SupplierReport;
import net.sf.jasperreports.engine.JRException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 供应商报表Service业务层处理
 *
 * @author wl
 * @date 2024-11-12
 */
@Service
public class SupplierReportServiceImpl implements ISupplierReportService {
    @Autowired
    private SupplierReportMapper supplierReportMapper;

    /**
     * 查询供应商报表列表
     *
     * @param supplierReport 供应商报表
     * @return 供应商报表
     */
    @Override
    public List<SupplierReport> selectSupplierReportList(SupplierReport supplierReport) {
        return supplierReportMapper.selectSupplierReportList(supplierReport);
    }

    /**
     * @return byte[]
     * @description 导出供货商pdf
     * @date 2024/11/15 下午4:51
     * @Param supplierReport:
     **/
    public byte[] printSupplierReport(SupplierReport supplierReport) throws JRException, FileNotFoundException {
        String templatePath = "jasper/SupplierReport.jrxml";
        Map<String, Object> paramsMap = new HashMap<>();
        paramsMap.put("createBy", SecurityUtils.getUsername());
        List<SupplierReport> list = supplierReportMapper.selectSupplierReportList(supplierReport);
        return JasperPdfUtil.exportPdfFromXml(templatePath, paramsMap, list);
    }
}
